@extends('layout.master')

@section('title','游戏详情')

@section('css')
    @parent
    <link href="{{ asset('plugins/bower_components/summernote/dist/summernote.css') }}" rel="stylesheet"/>
    <!-- animation CSS -->
    <link href="{{ asset('css/animate.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/icheck/skins/all.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.css') }}" rel="stylesheet">
@endsection
@section('main')
    <div class="white-box">
        <form class="form-horizontal form-material" method="post" enctype="multipart/form-data">
            <div class="row">
                <div class="col-md-3 col-sm-3">
                    <div class="row">
                        <div class="col-md-6 col-sm-6">
                            <div class="form-group">
                                <label class="col-md-12">每道题积分</label>
                                <div class="col-md-12">
                                    <input type="text" name="integral_pre" id="integral-pre"
                                           value="{{ $config->integral_pre }}"
                                           class="form-control form-control-line" required>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 col-sm-6">
                            <div class="form-group">
                                <label class="col-md-12">每日游戏次数</label>
                                <div class="col-md-12">
                                    <input type="text" name="game_times" id="game-times"
                                           value="{{ $config->game_times }}"
                                           class="form-control form-control-line" required>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-12 col-sm-12">
                            <div class="form-group">
                                <label class="col-md-12">奖励领取时限(天)</label>
                                <div class="col-md-12">
                                    <input type="text" name="price_limit" id="price-limit"
                                           value="{{ $config->price_limit }}"
                                           class="form-control form-control-line" required>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-12 col-sm-12">
                            <div class="form-group">
                                <label class="col-md-12">每次游戏出题数</label>
                                <div class="col-md-12">
                                    <input type="text" name="items_num" id="items-num"
                                           value="{{ $config->items_num }}"
                                           class="form-control form-control-line" required>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">游戏列表图片</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="list-pic" class="dropify" name="list_pic"
                                   data-default-file="{{ $config->list_pic }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">首页角色1</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="home-role1" class="dropify" name="home_role_1"
                                   data-default-file="{{ $config->home_role_1 }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">首页角色2</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="home-role2" class="dropify" name="home_role_2"
                                   data-default-file="{{ $config->home_role_2 }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">首页角色3</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="home-role3" class="dropify" name="home_role_3"
                                   data-default-file="{{ $config->home_role_3 }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">首页标题</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="home-title" class="dropify" name="home_title"
                                   data-default-file="{{ $config->home_title }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">首页背景</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="home-bg" class="dropify" name="home_bg"
                                   data-default-file="{{ $config->home_bg }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">首页晾衣杆</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="home-pole" class="dropify" name="home_pole"
                                   data-default-file="{{ $config->home_pole }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">首页开始按钮</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="home-start" class="dropify" name="home_start"
                                   data-default-file="{{ $config->home_start }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">首页游戏奖品</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="home-price" class="dropify" name="home_price"
                                   data-default-file="{{ $config->home_price }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">一等奖背景</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="home-price1" class="dropify" name="home_price1"
                                   data-default-file="{{ $config->home_price1 }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">二等奖背景</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="home-price2" class="dropify" name="home_price2"
                                   data-default-file="{{ $config->home_price2 }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">三等奖背景</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="home-price3" class="dropify" name="home_price3"
                                   data-default-file="{{ $config->home_price3 }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">游戏中答题框</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="gaming-box" class="dropify" name="gaming_box"
                                   data-default-file="{{ $config->gaming_box }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">游戏中陷阱</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="gaming-trap" class="dropify" name="gaming_trap"
                                   data-default-file="{{ $config->gaming_trap }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">游戏中背景</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="gaming-bg" class="dropify" name="gaming_bg"
                                   data-default-file="{{ $config->gaming_bg }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">游戏中虚线</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="gaming-dashed" class="dropify" name="gaming_dashed"
                                   data-default-file="{{ $config->gaming_dashed }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">游戏中正确按钮</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="gaming-true" class="dropify" name="gaming_true"
                                   data-default-file="{{ $config->gaming_true }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">游戏中正确按钮点击后</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="gaming-true-after" class="dropify" name="gaming_true_after"
                                   data-default-file="{{ $config->gaming_true_after }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">游戏中错误按钮</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="gaming-false" class="dropify" name="gaming_false"
                                   data-default-file="{{ $config->gaming_false }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">游戏中错误按钮点击后</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="gaming-false-after" class="dropify" name="gaming_false_after"
                                   data-default-file="{{ $config->gaming_false_after }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">排行榜总榜背景</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="rank-bg-all" class="dropify" name="rank_bg_all"
                                   data-default-file="{{ $config->rank_bg_all }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">排行榜自己背景</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="rank-bg-self" class="dropify" name="rank_bg_self"
                                   data-default-file="{{ $config->rank_bg_self }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">答完题答题框</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="answer-box" class="dropify" name="answer_box"
                                   data-default-file="{{ $config->answer_box }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">答完题返回首页</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="answer-back" class="dropify" name="answer_back"
                                   data-default-file="{{ $config->answer_back }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">十道题全部正确时弹窗</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="answer-success" class="dropify" name="answer_success"
                                   data-default-file="{{ $config->answer_success }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">答完题正确答案</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="answer-true" class="dropify" name="answer_true"
                                   data-default-file="{{ $config->answer_true }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">规则背景</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="rule-bg" class="dropify" name="rule_bg"
                                   data-default-file="{{ $config->rule_bg }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-3 col-sm-3">
                    <label class="col-md-12">关闭按钮</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="close" class="dropify" name="close"
                                   data-default-file="{{ $config->close }}"
                                   data-height="200px"/>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <label class="col-md-12">规则</label>
                <div class="col-md-12 col-sm-12">
                    <textarea name="contents" class="form-control" id="summernote" cols="30"
                              rows="5">{{ $config->rule_content }}</textarea>
                </div>
            </div>

        </form>
        <div class="form-group">
            <button class="fcbtn btn btn-success btn-outline btn-1e waves-effect" id="modify">修改
            </button>
        </div>
    </div>

    <!-- form itself -->
    <form id="add-role" class="mfp-hide white-popup-block floating-labels role-add" enctype="multipart/form-data">
        <h4><span>添加角色</span></h4>
        <hr>
        <div class="form-group m-b-40 m-t-10">
            <input type="file" id="role-add" class="dropify" name="add_role"
                   data-height="200px"/>
        </div>
        <div class="form-actions">
            <div class="row">
                <div class="col-md-12">
                    <div class="row">
                        <div class="col-md-offset-3 col-md-9">
                            <button type="submit" class="btn btn-success"><i
                                        class="fa fa-check"></i> 添加
                                {!! csrf_field() !!}
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>

    <div class="panel">
        <div class="panel-heading">
            <div class="panel-action" style="margin-top: -9px">
                <a class="popup-with-form btn fcbtn btn btn-outline btn-info btn-1c" href="#add-role">
                    <span>添加游戏角色</span>
                </a>
            </div>
        </div>
        <div class="panel-heading">游戏角色列表</div>
        <div class="panel-wrapper collapse in" aria-expanded="true">
            <div class="panel-body">
                <div class="table-responsive">
                    <table id="example23" class="display nowrap" cellspacing="0" width="100%"
                           data-url="{{ url('/runGame/role')}}">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>图片</th>
                            <th>删除</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

@endsection
@section('js')
    @parent
    <script src="{{ asset('js/myself.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/Magnific-Popup-master/dist/jquery.magnific-popup.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/Magnific-Popup-master/dist/jquery.magnific-popup-init.js') }}"></script>

    <script>

        $("#modify").click(function (e) {
            e.preventDefault();
            var integral_pre = $("#integral-pre").val();
            var game_times = $("#game-times").val();
            var price_limit = $("#price-limit").val();
            var items_num = $("#items-num").val();
            var rule_content = $("#summernote").val();
            var home_title = document.getElementById("home-title").files;
            var list_pic = document.getElementById("list-pic").files;
            var home_pole = document.getElementById("home-pole").files;
            var home_role_1 = document.getElementById("home-role1").files;
            var home_role_2 = document.getElementById("home-role2").files;
            var home_role_3 = document.getElementById("home-role3").files;
            var home_bg = document.getElementById("home-bg").files;
            var home_start = document.getElementById("home-start").files;
            var home_price = document.getElementById("home-price").files;
            var home_price1 = document.getElementById("home-price1").files;
            var home_price2 = document.getElementById("home-price2").files;
            var home_price3 = document.getElementById("home-price3").files;
            var gaming_box = document.getElementById("gaming-box").files;
            var gaming_trap = document.getElementById("gaming-trap").files;
            var gaming_bg = document.getElementById("gaming-bg").files;
            var gaming_dashed = document.getElementById("gaming-dashed").files;
            var gaming_true = document.getElementById("gaming-true").files;
            var gaming_true_after = document.getElementById("gaming-true-after").files;
            var gaming_false = document.getElementById("gaming-false").files;
            var gaming_false_after = document.getElementById("gaming-false-after").files;
            var rank_bg_all = document.getElementById("rank-bg-all").files;
            var rank_bg_self = document.getElementById("rank-bg-self").files;
            var answer_box = document.getElementById("answer-box").files;
            var answer_back = document.getElementById("answer-back").files;
            var answer_true = document.getElementById("answer-true").files;
            var answer_success = document.getElementById("answer-success").files;
            var rule_bg = document.getElementById("rule-bg").files;
            var close = document.getElementById("close").files;

            var data = new FormData();
            data.append('integral_pre', integral_pre);
            data.append('game_times', game_times);
            data.append('rule_content', rule_content);
            data.append('price_limit', price_limit);
            data.append('items_num', items_num);
            if (list_pic.length && ((list_pic[0].type).indexOf("image/") !== -1)) {
                data.append('list_pic', list_pic[0]);
            }
            if (home_title.length && ((home_title[0].type).indexOf("image/") !== -1)) {
                data.append('home_title', home_title[0]);
            }
            if (home_pole.length && ((home_pole[0].type).indexOf("image/") !== -1)) {
                data.append('home_pole', home_pole[0]);
            }
            if (home_role_1.length && ((home_role_1[0].type).indexOf("image/") !== -1)) {
                data.append('home_role_1', home_role_1[0]);
            }
            if (home_role_2.length && ((home_role_2[0].type).indexOf("image/") !== -1)) {
                data.append('home_role_2', home_role_2[0]);
            }
            if (home_role_3.length && ((home_role_3[0].type).indexOf("image/") !== -1)) {
                data.append('home_role_3', home_role_3[0]);
            }
            if (home_bg.length && ((home_bg[0].type).indexOf("image/") !== -1)) {
                data.append('home_bg', home_bg[0]);
            }
            if (home_start.length && ((home_start[0].type).indexOf("image/") !== -1)) {
                data.append('home_start', home_start[0]);
            }
            if (home_price.length && ((home_price[0].type).indexOf("image/") !== -1)) {
                data.append('home_price', home_price[0]);
            }
            if (home_price1.length && ((home_price1[0].type).indexOf("image/") !== -1)) {
                data.append('home_price1', home_price1[0]);
            }
            if (home_price2.length && ((home_price2[0].type).indexOf("image/") !== -1)) {
                data.append('home_price2', home_price2[0]);
            }
            if (home_price3.length && ((home_price3[0].type).indexOf("image/") !== -1)) {
                data.append('home_price3', home_price3[0]);
            }
            if (gaming_box.length && ((gaming_box[0].type).indexOf("image/") !== -1)) {
                data.append('gaming_box', gaming_box[0]);
            }
            if (gaming_trap.length && ((gaming_trap[0].type).indexOf("image/") !== -1)) {
                data.append('gaming_trap', gaming_trap[0]);
            }
            if (gaming_bg.length && ((gaming_bg[0].type).indexOf("image/") !== -1)) {
                data.append('gaming_bg', gaming_bg[0]);
            }
            if (gaming_dashed.length && ((gaming_dashed[0].type).indexOf("image/") !== -1)) {
                data.append('gaming_dashed', gaming_dashed[0]);
            }
            if (gaming_true.length && ((gaming_true[0].type).indexOf("image/") !== -1)) {
                data.append('gaming_true', gaming_true[0]);
            }
            if (gaming_true_after.length && ((gaming_true_after[0].type).indexOf("image/") !== -1)) {
                data.append('gaming_true_after', gaming_true_after[0]);
            }
            if (gaming_false.length && ((gaming_false[0].type).indexOf("image/") !== -1)) {
                data.append('gaming_false', gaming_false[0]);
            }
            if (gaming_false_after.length && ((gaming_false_after[0].type).indexOf("image/") !== -1)) {
                data.append('gaming_false_after', gaming_false_after[0]);
            }
            if (rank_bg_all.length && ((rank_bg_all[0].type).indexOf("image/") !== -1)) {
                data.append('rank_bg_all', rank_bg_all[0]);
            }
            if (rank_bg_self.length && ((rank_bg_self[0].type).indexOf("image/") !== -1)) {
                data.append('rank_bg_self', rank_bg_self[0]);
            }
            if (answer_box.length && ((answer_box[0].type).indexOf("image/") !== -1)) {
                data.append('answer_box', answer_box[0]);
            }
            if (answer_back.length && ((answer_back[0].type).indexOf("image/") !== -1)) {
                data.append('answer_back', answer_back[0]);
            }
            if (answer_true.length && ((answer_true[0].type).indexOf("image/") !== -1)) {
                data.append('answer_true', answer_true[0]);
            }
            if (answer_success.length && ((answer_success[0].type).indexOf("image/") !== -1)) {
                data.append('answer_success', answer_success[0]);
            }
            if (rule_bg.length && ((rule_bg[0].type).indexOf("image/") !== -1)) {
                data.append('rule_bg', rule_bg[0]);
            }
            if (close.length && ((close[0].type).indexOf("image/") !== -1)) {
                data.append('close', close[0]);
            }

            swal({
                    title: "",
                    text: "确定修改么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({

                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: "/runGame/config",
                        type: "POST",
                        data: data,
                        cache: false,
                        contentType: false,
                        async: false,
                        processData: false,
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },

                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            } else {
                                swal(data.message);
                            }
                        }
                    })
                }
            );
        });

        $('.role-add').submit(function (e) {
            e.preventDefault();
            var file = document.getElementById("role-add").files;
            if (!file.length) {
                swal('没有获取到图片');
                return false;
            }
            var formData = new FormData();
            formData.append('pic', file[0]);

            swal({
                    title: "",
                    text: "确定添加吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        type: "POST",
                        url: '/runGame/role/add',
                        data: formData,
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        cache: false,
                        contentType: false,
                        async: false,
                        processData: false,
                        error: function (err) {
                            for (var j in err.responseJSON) {
                                err.responseJSON[j].forEach(function (item, index) {
                                    swal(item);
                                })
                            }
                        },
                        success: function (data) {
                            console.log(data.message);
                            if (data.status === 1) {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            } else {
                                swal(data.message);
                            }
                        }
                    });
                }
            );
        });


        obj.on('click', '.btn-del', function () {
            var id = $(this).data('id');
            swal({
                    title: "",
                    text: "确定删除么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/runGame/role/del/' + id,
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });
    </script>
@endsection